package com.hdit.guimei.web;

import com.hdit.guimei.domain.Cart;
import com.hdit.guimei.domain.Goods;
import com.hdit.guimei.domain.Paygoods;
import com.hdit.guimei.service.impl.CartServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 张宝玉
 * @date 2021/1/19 10:39
 */
@Controller
public class CartController extends HttpServlet {
    @Autowired
    public CartServiceImpl cartService;
    /**
     *@methodName  findcartgoods
     *@方法功能描述：暂时返回值定位空
     *@params  [id, model]
     *@return  java.lang.String
     *@author   张宝玉
     *@Date    2021/1/19 10:44
     */
    @RequestMapping("/findcartgoods")
    @ResponseBody
    public String findcartgoods(int id, Model model){
        List<Cart> list = cartService.findcartgoods(id);
        model.addAttribute("cartgoodslist",list);
        return "ok";
    }
    /**
     *@methodName  payMoney
     *@方法功能描述：购物车 支付钱
     *@params  [id, good_id, buy_num, model]
     *@return  java.lang.String
     *@author   张宝玉
     *@Date    2021/1/19 14:14
     */
    @RequestMapping("/payMoney")
    public  String payMoney(@RequestBody Paygoods paygoods,Model model){
        double money = cartService.payMoney(paygoods);
        model.addAttribute("money",money);
        return "";
    }
    /**
     *@methodName  delecartgoods
     *@方法功能描述：删除商品 修改购物车商品状态 传过来
     *@params  [id, good_id]
     *@return  java.lang.String
     *@author   张宝玉
     *@Date    2021/1/19 14:36
     */
    @RequestMapping("/delecartgoods")
    @ResponseBody
    public String delecartgoods(@RequestBody Paygoods paygoods){
        List<Cart> list = paygoods.getCartList();
        for (int i = 0; i < list.size(); i++) {
            int i1 = cartService.delecartgoods(paygoods.getUser_id(), list.get(i).getGood_id());
        }
        return "";
    }

    @RequestMapping("/addShoppingCart")
    @ResponseBody
    public Map addShoppingCart(@RequestBody Map<String,String> param){
        Map map=new HashMap();

        return map;
    }
}
